package initAll;

import org.apache.logging.log4j.core.LogEventListener;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.events.EventFiringWebDriver;

public class getWebDriver {
	private static WebDriver driver;
	private static DesiredCapabilities caps;
	
	/**
	 * 
	 * @param ie
	 * @return
	 *(1) NONE: 当html下载完成之后，不等待解析完成，selenium会直接返回
	 *(2) EAGER: 要等待整个dom树加载完成，即DOMContentLoaded这个事件完成，仅对html的内容进行下载解析
	 *(3) NORMAL: 即正常情况下，selenium会等待整个界面加载完成（指对html和子资源的下载与解析,如JS文件，图片等，不包括ajax）
	 * 
	 * 
	 */
	public static WebDriver setInternetIE(String ie){
		switch(ie){
		case "firefox":
			caps=DesiredCapabilities.firefox();
			caps.setPlatform(Platform.WINDOWS);
			caps.setBrowserName("firefox");
			caps.setCapability("pageLoadStrategy", "normal");
			System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
			System.setProperty("webdriver.gecko.driver", "E:/selenium IE Driver/geckodriver.exe");
			driver=new FirefoxDriver(caps);
			break;
		case "chrome":
			caps=DesiredCapabilities.chrome();
			caps.setPlatform(Platform.WINDOWS);
			caps.setBrowserName("chrome");
			caps.setCapability("pageLoadStrategy", "normal");
			System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY,"true");
			System.setProperty("webdriver.chrome.driver", "E:/selenium IE Driver/chromedriver.exe");
			driver=new ChromeDriver(caps);
			break;
		case "ie":
			caps=DesiredCapabilities.internetExplorer();
			caps.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
			caps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,false);
			caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
			caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
			caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
			caps.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
			caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
			caps.setPlatform(Platform.WINDOWS);
			caps.setCapability("pageLoadStrategy", "normal");
			caps.setBrowserName("chrome");
			System.setProperty("webdriver.ie.driver", "E:/selenium IE Driver/IEDriverServerX64.exe");
			driver=new InternetExplorerDriver(caps);
			break;
		case "edge":
			caps=DesiredCapabilities.edge();
			caps.setPlatform(Platform.WINDOWS);
			caps.setBrowserName("edge");
			System.setProperty("webdriver.edge.driver", "E:/selenium IE Driver/msedgedriver.exe");
			driver=new EdgeDriver();
			break;	
		}
		return driver;
	}
}
